<template>
	<view class="container">
		<uni-search-bar style="background-color: #fff;" placeholder="请输入分类名称进行查询" @confirm="getDataList"
			v-model="queryParam.Keyword" @cancel="cancel">
		</uni-search-bar>
		<uni-list>
			<uni-list-item v-for="item in data" :key="item.Id" :title="item.Name" showArrow clickable
				@click="toForm(item.Id)">
				<template v-slot:footer>
					<view @click.stop="()=>{}">
						<uni-icons @click="del(item.Id)" color="red" type="trash"></uni-icons>
					</view>
				</template>
			</uni-list-item>
		</uni-list>
		<view style="height: 120rpx;">

		</view>
		<view class="tabbar">
			<view class="submitOrder" @click="submitOrderCart">
				去复制
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				data: [],
				pagination: {
					PageIndex: 1,
					PageRows: 30,
					SortField: "CreateTime",
					SortType: "desc",
				},
				total: 0,
				queryParam: {
					"Condition": "Name",
					"Keyword": "",
				},
			}
		},
		onNavigationBarButtonTap(e) {
			console.log(e);
			uni.navigateTo({
				url: '/pages/Information/page/GoodsType/GoodsTypeForm'
			})
		},
		onLoad() {
			this.queryParam.CommpayId = uni.getStorageSync('CompanyInfo').Id
		},
		onShow() {
			this.pagination.PageIndex = 1
			this.getDataList()
		},
		onReachBottom() {
			if (this.data.length >= this.total) return
			this.pagination.PageIndex++
			uni.showLoading()
			this.$http('post', '/BO/InventType/GetDataList', {
					...this.pagination,
					Search: this.queryParam
				})
				.then(res => {
					uni.hideLoading()
					if (res.Success) {
						this.data = this.data.concat(res.Data)
						this.total = res.Total
					} else uni.showToast({
						icon: 'none',
						title: res.Msg
					})
				})
		},
		methods: {
			del(Id) {
				uni.showModal({
					title: '提示',
					content: '确认删除此分类吗?',
					success: (val) => {
						if (val.confirm) {
							this.$http('post', '/BO/InventType/DeleteData', [Id]).then(res => {
								if (res.Success) {
									this.$api.msg('操作成功')
									this.getDataList()
								} else this.$api.msg(res.Msg)
							})
						}
					}
				})
			},
			// 去复制
			submitOrderCart() {
				uni.navigateTo({
					url: '/pages/Information/page/GoodsType/GoodsTypeCoye'
				})
			},
			getDataList() {
				uni.showLoading()
				this.$http('post', '/BO/InventType/GetDataList', {
						...this.pagination,
						Search: this.queryParam
					})
					.then(res => {
						uni.hideLoading()
						if (res.Success) {
							this.data = res.Data
							this.total = res.Total
						} else uni.showToast({
							icon: 'none',
							title: res.Msg
						})
						console.log(this.total);
					})
			},
			toForm(id) {
				uni.navigateTo({
					url: '/pages/Information/page/GoodsType/GoodsTypeForm?Id=' + id
				})
			},
			cancel() {
				this.queryParam.Keyword = ''
				this.getDataList()
			}
		}
	}
</script>

<style scoped lang="less">
	.container {

		// 底部导航
		.tabbar {
			display: flex;
			width: 100%;
			height: 120rpx;
			padding: 0 30rpx;
			box-sizing: border-box;
			background-color: #ffffff;
			position: fixed;
			bottom: 0;
			border-top: 1px solid #E0E0E0;
			display: flex;
			align-items: center;
			justify-content: flex-end;

			.submitOrder {
				width: 208rpx;
				height: 80rpx;
				background-image: linear-gradient(to right, #38FFCB, #2979FF);
				border-radius: 60rpx;
				font-size: 30rpx;
				font-weight: bold;
				color: #FFFFFF;
				letter-spacing: 2.57rpx;
				display: flex;
				align-items: center;
				justify-content: center;
			}
		}
	}
</style>